package com.jiacl.filter;

import com.google.gson.Gson;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * Created by XiaoWei on 2017/10/20.
 */
@ControllerAdvice
public class Aaaaaa {
    @ModelAttribute
    public void f(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        String s = "";
        System.out.println(Arrays.stream(cookies).map(cookie -> cookie.getName() + ": " + cookie.getValue()).collect(Collectors.joining()));
        Optional<Cookie> token = Arrays.stream(cookies).filter(cookie -> cookie.getName().equals("token")).findAny();
        System.out.println(token);
//        System.out.println("token" +new Gson().toJson(request) );
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String s1 = headerNames.nextElement();
            System.out.println(s1);
        }
    }

}
